/**
 * Created by CHONGE on 2017/12/1.
 */
//初始化所有的图表
var dataEchart = {
    //折线图
    brokenLineData: function (objData) {
        var colors = ['#CD00CD', '#C0FF3E', '#A020F0'];
        var option = {
            color: colors,
            grid: {
                top: 30,
                bottom: 100,
                left:70,
                right:'4%',
                height:280
            },
            tooltip: {
                trigger: 'axis',
                /*axisPointer: {
                    type: 'cross'
                }*/
            },
            xAxis: [

                {
                    type: 'category',
                    axisTick: {
                        alignWithLabel: true
                    },
                    axisLabel: {
                        interval: 1,
                        rotate: 30
                    },
                    axisLine: {
                        onZero: false,
                        lineStyle: {
                            color: colors[0]
                        }
                    },
                    axisPointer: {
                        label: {
                            formatter: function (params) {
                                return ' ' + params.value
                                    + (params.seriesData.length ? '：' + params.seriesData[0].data : '');
                            }
                        }
                       // snap:true
                    },
                    data: objData.xTime
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [

                {
                    name: '数量',
                    itemStyle: {normal: {label: {show: true}}},
                    type: 'line',
                    smooth: true,
                    data: objData.yValue,
                }
            ]
        };

        return option;
    },


    // 饼图 玫瑰图
    pieData: function (barData) {
        var option = {
            color: ['#b15bff', '#ff00ff', '#00caca', '#ae57a4', '#ff8040', '#2894ff'],
            label: {
                normal: {
                    show: true,
                    formatter: '{b} :\n {c} ({d}%)',
                    position: "insideTopRight"
                },
                emphasis: {
                    show: true,
                    formatter: '{b} :\n {c} ({d}%)',
                    position: "insideTopRight"
                }
            },
            series: {
                type: 'pie',
                startAngle: 10,
                minAngle: 5,
                radius: ['30%', '60%'],
                roseType: 'angle',
                itemStyle: {

                    emphasis: {
                        //阴影的大小
                        shadowBlur: 50,
                        // 阴影水平方向上的偏移
                        shadowOffsetX: 0,
                        // 阴影垂直方向上的偏移
                        shadowOffsetY: 0,
                        // 阴影颜色
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                },
                data: barData

            }
        }
        return option;
    },
    //柱图
    columnChartData: function (data) {
        var option = {
            tooltip: {
                trigger: 'item',
            },
            grid: {
                top: 30,
                bottom: 55,
                left:80,
                right:70,
            },
            xAxis: {
                data: data.xName,
                axisTick: {
                    show: false
                },
                axisLine: {
                    show: false
                },
                axisLabel: {
                    interval: 0
                },
                z: 10
            },
            yAxis: {
                axisLine: {
                    show: true,
                    lineStyle: {
                        color: '#999'
                    }
                },
                axisTick: {
                    show: false
                },
                axisLabel: {
                    textStyle: {
                        color: '#999'
                    }
                }
            },
            series: [
                { // For shadow
                    type: 'bar',
                    itemStyle: {
                        normal: {color: 'rgba(0,0,0,0.05)'}
                    },
                    barGap: '-100%',
                    barCategoryGap: '40%',
                    animation: false
                },
                {
                    type: 'bar',
                    barMaxWidth: 30,
                    data: data.yValue
                }
            ]
        };
        return option;
    },

    //折线面积图
    columAreaData: function (dataMap) {
        var base = +new Date(1968, 9, 3);
        var oneDay = 24 * 3600 * 1000;
        var date = [];
        var data = [Math.random() * 300];
        for (var i = 1; i < 20000; i++) {
            var now = new Date(base += oneDay);
            date.push([now.getFullYear(), now.getMonth() + 1, now.getDate()].join('/'));
            data.push(Math.round((Math.random() - 0.5) * 20 + data[i - 1]));
        }
        var option = {
            tooltip: {
                trigger: 'axis',
                position: function (pt) {
                    return [pt[0], '10%'];
                }
            },
            grid: {
                top: 30,
                bottom: 55,
                left:70,
                right:70,
            },
            xAxis: {
                type: 'category',
                axisLabel: {
                    interval: 0,
                    rotate: 30
                },
                boundaryGap: false,
                data: dataMap.xTime
            },
            yAxis: {
                type: 'value',
                boundaryGap: [0, '100%']
            },
            series: [
                {
                    name: '数量',
                    type: 'line',
                    smooth: true,
                    //symbol: 'none',
                    sampling: 'average',
                    itemStyle: {
                        normal: {
                            color: 'rgb(255, 70, 131)'
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: 'rgb(255, 158, 68)'
                            }, {
                                offset: 1,
                                color: 'rgb(255, 70, 131)'
                            }])
                        }
                    },
                    data: dataMap.yValue
                }
            ]
        };
        return option;
    },
    //地图分布
    mapData: function (mapList) {
        var option = {
            tooltip: {
                trigger: 'item',
                formatter:function (params) {
                    if(params.value){
                        return params.name+' : '+params.value;
                    }else{
                        return params.name+' : '+0;
                    }
                }
            },
            visualMap: {
                seriesIndex: 0,
                min: 0,
                // max: 800,
                left: '5%',
                right:'8%',
                bottom:'2%',
                // top: 'bottom',
                text: ['高', '低'],           // 文本，默认为数值文本
                //calculable: true,
                padding: [0,0,15,0],
            },
            grid: {
                height: 200,
                width: 8,
                right: 80,
                bottom: 20
            },
            xAxis: {
                type: 'category',
                data: [],
                splitNumber: 1,
                show: false
            },
            yAxis: {
                position: 'right',
                min: 0,
                max: 20,
                splitNumber: 20,
                inverse: true,
                axisLabel: {
                    show: true
                },
                axisLine: {
                    show: false
                },
                splitLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                data: []
            },
            series: [
                {
                    zlevel: 1,
                    name: '中国',
                    type: 'map',
                    mapType: 'china',
                    roam: false,
                    right: '4%',
                    width:'78%',
                    height:"90%",
                    bottom:26,
                    label: {
                        normal: {
                            show: true
                        },
                        emphasis: {
                            show: true
                        }
                    },
                    itemStyle:{
                        normal:{
                            label:{show:true},
                            borderWidth:1,//省份的边框宽度
                            borderColor:'#c042ff',//省份的边框颜色
                            color:'#61c1ec'//地图背景颜色
//areaStyle:{color:'#f60'}//设置地图颜色
                        },},
                    data: mapList
                },
            ]
        };
        return option;
    },
//环形饼图
    pieCircularData: function (pieData,name) {
        var option = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b}: {c} ({d}%)"
            },
            series: [
                {
                    name:name,
                    type:'pie',
                    selectedMode: 'single',
                    radius: [0, '30%'],
                    center: ['50%', '50%'],
                    label: {
                        normal: {
                            position: 'inner'
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    }

                },
                {
                    name: name,
                    type: 'pie',
                    radius: ['40%', '55%'],
                    label: {
                        normal: {
                            formatter: '{a}\n {b}{c}  {d}%',
                            backgroundColor: '#eee',
                            borderColor: '#aaa',
                            borderWidth: 1,
                            borderRadius: 4,
                            // formatter:'{d}%',
                            rich: {
                                a: {
                                    color: '#999',
                                    lineHeight: 22,
                                    align: 'center'
                                },

                                hr: {
                                    borderColor: '#aaa',
                                    width: '100%',
                                    borderWidth: 0.5,
                                    height: 0
                                },
                                b: {
                                    fontSize: 16,
                                    lineHeight: 33
                                },
                                per: {
                                    color: '#eee',
                                    backgroundColor: '#334455',
                                    padding: [2, 4],
                                    borderRadius: 2
                                }
                            }
                        }
                    },
                    data: pieData
                }
            ]
        };
        return option;
    }
};

